const YmlService = require("./yml.service")

class Util {
  random = (lib = []) => lib[Math.floor(Math.random() * lib.length)]
  /** 组合算法，从m中选取n个数进行组合
   * @param {any[]} arr
   * @param {number} size
   */
  choose(arr, size) {
    var allResult = [];

    const runner = (arr, size, result) => {
      var arrLen = arr.length;
      if (size > arrLen) {
        return;
      }
      if (size == arrLen) {
        allResult.push([].concat(result, arr))
      } else {
        for (var i = 0; i < arrLen; i++) {
          var newResult = [].concat(result);
          newResult.push(arr[i]);

          if (size == 1) {
            allResult.push(newResult);
          } else {
            var newArr = [].concat(arr);
            newArr.splice(0, i + 1);
            runner(newArr, size - 1, newResult);
          }
        }
      }
    }

    runner(arr, size, []);

    return allResult;
  }
}

export default new Util()
